package weaver.splittable.db.oracle;

import weaver.splittable.db.STDBConstants;
import weaver.splittable.db.STSyncClearSqlUtil;

public class STOracleSyncSqlUtil implements STSyncClearSqlUtil {

    private static final String SELECT_DATA_CHANGE_SQL = "SELECT * FROM "+ STDBConstants.DATA_CHANGE_TABLE_NAME +" where synced='0' and rownum <= %s";
    private static final String SELECT_DATA_CHANGE_ALL_SQL = "SELECT * FROM "+ STDBConstants.DATA_CHANGE_TABLE_NAME +" where synced='0'";

    private static final String CLEAR_DATA_CHANGE_INFO_SQL = "delete from "+ STDBConstants.DATA_CHANGE_TABLE_NAME +" where rownum <= 1000 and synced <> '0' and sync_time is not null and sync_time < '%s'";
    private static final String CLEAR_DATA_CLEAR_INFO_SQL = "delete from "+ STDBConstants.DATA_CLEAR_TABLE_NAME +" where rownum <= 1000 and synced <> '0' and sync_time is not null and sync_time < '%s'";

    @Override
    public String selectDataChange(Integer count) {
        if (count == null) {
            return SELECT_DATA_CHANGE_ALL_SQL;
        } else {
            return String.format(SELECT_DATA_CHANGE_SQL, count);
        }
    }

    @Override
    public String clearDataChangeInfo(Long clearTime) {
        return String.format(CLEAR_DATA_CHANGE_INFO_SQL, clearTime);
    }

    @Override
    public String clearDataClearInfo(Long clearTime) {
        return String.format(CLEAR_DATA_CLEAR_INFO_SQL, clearTime);
    }

}

